package biz.datalk.industrialland.admin.modules.externalapi.model.vo;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.io.Serializable;

/**
 * @author tarofang@163.com
 * @date 2023-03-30
 */
@Getter
@Setter
@ToString
public class SmsResult implements Serializable {
    private static final long serialVersionUID = 1L;

    public static final String CODE_SUCCESS = "0";
    public static final String CODE_FAIL_REQUEST_PARAMS = "-1";
    public static final String CODE_FAIL_RESPONSE_RESULT = "-2";

    private String code;
    private String message;
    private Object data;

    private boolean success;

    public static SmsResult fail(String errCode, String errMsg) {
        return fail(errCode, errMsg, null);
    }

    public static SmsResult fail(String errCode, String errMsg, Object data) {
        return create(Boolean.FALSE, errCode, errMsg, data);
    }

    public static SmsResult success(String errCode, String errMsg, Object data) {
        return create(Boolean.TRUE, errCode, errMsg, data);
    }

    public static SmsResult create(boolean isSuccess, String errCode, String errMsg, Object data) {
        SmsResult result = new SmsResult();
        result.setSuccess(isSuccess);
        result.setCode(errCode);
        result.setMessage(errMsg);
        result.setData(data);
        return result;
    }

    /** 自定义错误码， -1 表示请求参数错误 */
    public static SmsResult reqParamInvalid(String errMsg) {
        return fail(CODE_FAIL_REQUEST_PARAMS, errMsg);
    }

    /** 自定义错误码， -2 表示响应数据错误 */
    public static SmsResult resResultInvalid(String errMsg) {
        return fail(CODE_FAIL_RESPONSE_RESULT, errMsg);
    }

}
